#源jar路径绝对路径
#检查端口是否占用 占用会启动不成功
SOURCE_PATH=/root/fastjson/
SOURCE_NAME=fastjson-0.0.1-SNAPSHOT.jar
SOURCE_PORT="8080"
echo "************** 查找进程 ****************"
pid=$(ps -ef | grep "$SOURCE_NAME" | grep -v grep | awk '{print $2}')
if [ -n "$pid" ]; then
        echo "${SOURCE_NAME}进程id: $pid"
        kill -9 "$pid"
        if [ "$?" -eq 0 ]; then
                echo -e "\033[31mkill $pid 成功!\033[0m"
        else
                echo -e "\033[31mkill 失败\033[0m"
        fi
fi
echo "************ 检查端口占用 **************"
port=$(netstat -nlp |grep :"${SOURCE_PORT}" | awk '{print $7}')
port=${port%%/*}
if [ ${#port} -gt 1  ]; then
        echo "端口占用-进程id: $port"
        kill -9 "$port"
        echo "开始 kill ${SOURCE_PORT} 端口占用进程!"
        if [ "$?" -eq 0 ]; then
                echo -e "\033[31mkill $port 成功!\033[0m"
        else
                echo -e "\033[31mkill $port 失败\033[0m"
        fi
fi

nohup java -jar "${SOURCE_PATH}""${SOURCE_NAME}" --Dspring.config.location="${SOURCE_PATH}"config/* >/dev/null 2>&1 &
echo "************** 启动成功 ****************"
exit 0